<template>
  <!-- main start -->
  <div class="contianer">
    <div class="c_right">
      <h1>乐现云课堂后台管理系统</h1>    
      <!-- <form action = "{:U('Home/Login/login')}" method="post" id="login" > -->
      <form id="login" >
        <ul>
          <li>
            <input type="text" name="username" v-model="username" id="userName" placeholder="请输入用户名">
          </li>
          <li>
            <input type="password" name="password" v-model="password" id="password" placeholder="请输入密码">
          </li>
          <li>
            <input type="text" name="code" value="" id="imgCode" placeholder="请输入验证码">
            <span class="imgCode">
              <!-- <img src="{:U('Home/Login/verify')}" id="code" /><a href="javascript:void(change_code(this));">换一个</a> -->
            </span>
          </li>
          <li>
            <div id="submit" @click="login" >登 录</div>
          </li>
        </ul>
      </form>
      <!-- <h2><a href="{:U('Home/Login/findPassword')}">忘记登录密码？</a></h2> -->
    </div>
  </div>
  <!-- main end -->
</template>

<script>
import axios from 'axios'

export default {
  name: 'hello',
  data () {
    return {
      msg: 'Welcome to Your Vue.js App',
      username: "admin",
      password: "123456",
      error: ''
    }
  },
  methods: {
    login() {
      console.log(this)
      console.log(this.username)
      console.log(this.password)
      let username = this.username
      let password = this.password

      if(username=='admin'&&password=='123456'){
        localStorage.isLogin = true;
        this.$router.replace(this.$route.query.redirect || '/productBaseService')
      } else {
        this.error = 'error username or password'
      }

      /**
       * 拼接对象为请求字符串
       * @param {Object} obj - 待拼接的对象
       * @returns {string} - 拼接成的请求字符串
       */
      function encodeSearchParams(obj) {
        const params = []

        Object.keys(obj).forEach((key) => {
          let value = obj[key]
          // 如果值为undefined我们将其置空
          if (typeof value === 'undefined') {
            value = ''
          }
          // 对于需要编码的文本（比如说中文）我们要进行编码
          params.push([key, encodeURIComponent(value)].join('='))
        })

        return params.join('&')
      }

      // 异步请求 
      // axios.get('http://192.168.2.252:8000/TP-webpack/index.php')
      //   .then(function (response) {
      //     console.log(response);
      //     localStorage.username = username
      //     localStorage.password = password
      //   })
      //   .catch(function (error) {
      //     console.log(error);
      //   });

      // axios.get('http://192.168.2.251/TPJoyschoolYxp/index.php/Index/html1')
      //   .then(function (response) {
      //     console.log(response);
      //     localStorage.username = username
      //     localStorage.password = password
      //   })
      //   .catch(function (error) {
      //     console.log(error);
      //   });
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

.header{width: 100%; height: 90px;}
.h_left{float: left; margin-left: 15%; width: 180px; height: 90px; }
.h_left img{ height: 100%; }
.h_right{float: right; margin-right: 15%; width: 220px; height: 90px; }
.h_right p{ color: #333; line-height: 90px;}

h1, h2 {
  font-weight: normal;
}

ul {
  list-style-type: none;
  padding: 0;
}

li {
  display: inline-block;
  margin: 0 10px;
}

a {
  color: #42b983;
}
</style>
